define(["../common"], function() {
	var $form = $("#form_login");
	
	var formCfg = {
		fields: {
			name: "账户名:required",
			password: "密码:required"
		}
	}
	
	requirePlugin(["validator"], function() {
		$form.validator(formCfg);
	});
	
	$("a.checkbox").click(function() {
		$(this).trigger('check');
		return false;
	});
	
	$form.on('valid.form', function(e, form){
		$form.loadMsg("正在登录...");
		$.post(g_domain + "/member/loginDo/json",$form.serialize(), function(data){
			if (data.status != 0) {
				$form.failMsg(data.message);
				return;
			} 
			$form.infoMsg("登录成功...");
			Member.checkLogin(function(member) {
				if (data.result) {
					location.href = data.result;
				} else {
					location.href = g_userDomain;
				}
			}, true);
				
		});
	});
	
});